package minijvm.cmd;

import minijvm.clz.ClassFile;
import minijvm.engine.ExecutionResult;
import minijvm.engine.Heap;
import minijvm.engine.JavaObject;
import minijvm.engine.StackFrame;

/**
 * @author ChangLiang
 * @date 2020/4/30
 */
public class IncrementCmd extends TwoOperandCmd {

    public IncrementCmd(ClassFile clzFile, String opCode) {
        super(clzFile, opCode);
    }

    @Override
    public void execute(StackFrame frame, ExecutionResult result) {
        int slot = this.getOprand1();
        int constValue = this.getOprand2();
        int currentValue = frame.getLocalVariableValue(slot).getIntValue();
        JavaObject javaObject = Heap.getInstance().newInt(constValue + currentValue);
        frame.setLocalVariableValue(slot,javaObject);
    }
}
